home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 322 / flex / flexfast.skl < prev    next >
Encoding:
Text File  |  1988-10-20  |  10.1 KB  |  433 lines

  1. /* A lexical scanner generated by flex */
  2.  
  3. #define FLEX_FAST_SKEL
  4.  
  5. #ifdef atarist
  6. #include "flexskfa.h"
  7. #else
  8. #include "fastskeldef.h"
  9. #endif
  10.  
  11. %% section 1 code and the definition of YY_TRANS_OFFSET_TYPE, if needed, go here
  12.  
  13. #ifndef FLEX_FULL_TABLE
  14.     /* struct for yy_transition */
  15.     struct yy_trans_info
  16.     {
  17.     /* v is a verify for a transition. */
  18.     short v;
  19.  
  20.     /* In cases where its sister v *is* a "yes, there is a transition",
  21.          * n is* the offset (in records) to the next state.  In most cases
  22.          * where there is no transition, the value of n is irrelevant.  If n
  23.          * is the -1th  record of a state, though, then n is the action
  24.      * number for that state
  25.      */
  26.     YY_TRANS_OFFSET_TYPE n;
  27.     };
  28. #endif
  29.  
  30. %% data tables for DFA go here
  31.  
  32. /* these declarations have to come after the section 1 code or lint gets
  33.  * confused about whether the variables are used
  34.  */
  35. FILE *yyin = stdin, *yyout = stdout;
  36.  
  37. /* these variables are all declared out here so that section 3 code can
  38.  * manipulate them
  39.  */
  40. static char *yy_c_buf_p;    /* points to current character in buffer */
  41. static char *yy_b_buf_p;    /* points to start of current scan */
  42. static int yy_init = 1;    /* whether we need to initialize */
  43. static int yy_start;    /* start state number */
  44.  
  45. /* true when we've seen an EOF for the current input file */
  46. static int yy_eof_has_been_seen;
  47.  
  48. static int yy_n_chars;        /* number of characters read into yy_ch_buf */
  49.  
  50. /* yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
  51.  * to put in 2 end-of-buffer characters (this is explained where it is
  52.  * done) at the end of yy_ch_buf
  53.  */
  54. static char yy_ch_buf[YY_BUF_SIZE + 2];
  55.  
  56. /* yy_hold_char holds the character lost when yytext is formed */
  57. static char yy_hold_char;
  58. char *yytext;
  59. static int yyleng;    /* length of yytext */
  60.  
  61. static YY_CS_TYPE yy_last_accepting_state;
  62. static char *yy_last_accepting_cpos;
  63.  
  64. static YY_CS_TYPE yy_get_previous_state();
  65. static int yy_get_next_buffer();
  66.  
  67. #define FLEX_USES_BACKTRACKING
  68.  
  69. #ifdef atarist
  70.  
  71. #ifdef FLEX_USES_BACKTRACKING
  72. #    ifdef FLEX_FULL_TABLE
  73. #    define YY_BACKTRACKING_ACTION \
  74.         if ( __l[yy_current_state] ) \
  75.             { \
  76.             yy_last_accepting_state = yy_current_state; \
  77.             yy_last_accepting_cpos = yy_c_buf_p; \
  78.             }
  79. #    else
  80. #    define YY_BACKTRACKING_ACTION \
  81.         if ( yy_current_state[-1].n ) \
  82.             { \
  83.             yy_last_accepting_state = yy_current_state; \
  84.             yy_last_accepting_cpos = yy_c_buf_p; \
  85.             }
  86. #    endif
  87. #else
  88. #    define YY_BACKTRACKING_ACTION
  89. #endif
  90.  
  91. #else    /* atari */
  92.  
  93. #ifdef FLEX_USES_BACKTRACKING
  94. #    ifdef FLEX_FULL_TABLE
  95. #    define YY_BACKTRACKING_ACTION \
  96.         if ( l[yy_current_state] ) \
  97.             { \
  98.             yy_last_accepting_state = yy_current_state; \
  99.             yy_last_accepting_cpos = yy_c_buf_p; \
  100.             }
  101. #    else
  102. #    define YY_BACKTRACKING_ACTION \
  103.         if ( yy_current_state[-1].n ) \
  104.             { \
  105.             yy_last_accepting_state = yy_current_state; \
  106.             yy_last_accepting_cpos = yy_c_buf_p; \
  107.             }
  108. #    endif
  109. #else
  110. #    define YY_BACKTRACKING_ACTION
  111. #endif
  112.  
  113. #endif /* atari */
  114.  
  115. YY_DECL
  116.     {
  117.     register YY_CS_TYPE yy_current_state;
  118.     register int yy_c;
  119.     register struct yy_trans_info *yy_trans_info;
  120.     register int yy_act;
  121.  
  122. %% user's declarations go here
  123.  
  124.     if ( yy_init )
  125.     {
  126.     yy_start = 1;    /* first start state */
  127.  
  128. new_file:
  129.     /* this is where we enter upon encountering and end-of-file and
  130.      * yywrap() indicating that we should continue processing
  131.      */
  132.  
  133.     /* we put in the '\n' and start reading from [1] so that an
  134.      * initial match-at-newline will be true.
  135.      */
  136.  
  137.     yy_ch_buf[0] = '\n';
  138.     yy_n_chars = 1;
  139.  
  140.     /* we always need two end-of-buffer characters.  The first causes
  141.      * a transition to the end-of-buffer state.  The second causes
  142.      * a jam in that state.
  143.      */
  144.     yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  145.     yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  146.  
  147.     yy_eof_has_been_seen = 0;
  148.  
  149.     YY_FAST_INIT;
  150.     yy_init = 0;
  151.     }
  152.  
  153.     while ( 1 )        /* loops until end-of-file is reached */
  154.     {
  155.     /* support of yytext and yyleng */
  156.     YY_DO_BEFORE_SCAN;
  157.  
  158.     /* yy_b_buf_p points to the position in yy_ch_buf of the start of the
  159.      * current run.
  160.      */
  161.     yy_b_buf_p = yy_c_buf_p;
  162.  
  163.         YY_FIND_START_STATE( yy_current_state );
  164.  
  165.         YY_FIND_NEXT_MATCH;
  166.  
  167.     YY_DO_BEFORE_ACTION;
  168.  
  169. /* we need this label to process the very last action (right before the end of
  170.  * the file)
  171.  */
  172. do_action:
  173.     YY_FIND_ACTION( yy_act );
  174.  
  175. #ifdef FLEX_DEBUG
  176.     fprintf( stderr, "--accepting rule #%d\n", yy_act );
  177. #endif
  178.     switch ( yy_act )
  179.         {
  180. %% actions go here
  181.  
  182.         case YY_BACK_TRACK:
  183.         YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  184.         yy_c_buf_p = yy_last_accepting_cpos + 1;
  185.         yy_current_state = yy_last_accepting_state;
  186.         YY_DO_BEFORE_ACTION;
  187.         goto do_action;
  188.  
  189.         case YY_NEW_FILE:
  190.         break; /* begin reading from new file */
  191.  
  192.         case YY_DO_DEFAULT:
  193.         /* we have to eat up one character and recompute yytext and
  194.          * yyleng
  195.          */
  196.         YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  197.         ++yy_c_buf_p;
  198.         YY_DO_BEFORE_ACTION;
  199.         YY_DEFAULT_ACTION;
  200.         break;
  201.  
  202.         case YY_END_OF_BUFFER:
  203.         YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  204.  
  205.         switch ( yy_get_next_buffer() )
  206.             {
  207.             case EOB_ACT_END_OF_FILE:
  208.             {
  209.             if ( yywrap() )
  210.                 {
  211.                 /* note: because we've taken care in
  212.                  * yy_get_next_buffer() to have set up yy_b_buf_p,
  213.                  * we can now set up yy_c_buf_p so that if some
  214.                  * total hoser (like flex itself) wants
  215.                  * to call the scanner after we return the
  216.                  * YY_NULL, it'll still work - another YY_NULL
  217.                   * will get returned.
  218.                  */
  219.                 yy_c_buf_p = yy_b_buf_p;
  220.                 return ( YY_NULL );
  221.                 }
  222.  
  223.             else
  224.                 goto new_file;
  225.             }
  226.             break;
  227.  
  228.             case EOB_ACT_RESTART_SCAN:
  229.             yy_c_buf_p = yy_b_buf_p;
  230.  
  231.             YY_DO_BEFORE_RESTART;
  232.             break;
  233.  
  234.             case EOB_ACT_LAST_MATCH:
  235.             yy_c_buf_p = &yy_ch_buf[yy_n_chars];
  236.  
  237.             yy_current_state = yy_get_previous_state();
  238.  
  239.             YY_DO_BEFORE_ACTION;
  240.  
  241.             goto do_action;
  242.             }
  243.         break;
  244.  
  245.         default:
  246.         printf( "action # %d\n", yy_act );
  247.         YY_FATAL_ERROR( "fatal flex scanner internal error" );
  248.         }
  249.     }
  250.     }
  251.  
  252.  
  253. /* yy_get_next_buffer - try to read in new buffer
  254.  *
  255.  * synopsis
  256.  *     int yy_get_next_buffer();
  257.  *     
  258.  * returns a code representing an action
  259.  *     EOB_ACT_LAST_MATCH - 
  260.  *     EOB_ACT_RESTART_SCAN - restart the scanner
  261.  *     EOB_ACT_END_OF_FILE - end of file
  262.  */
  263.  
  264. static int yy_get_next_buffer()
  265.  
  266.     {
  267.     if ( yy_c_buf_p != &yy_ch_buf[yy_n_chars + 1] )
  268.     {
  269.     YY_FATAL_ERROR( "NULL in input" );
  270.     /*NOTREACHED*/
  271.     }
  272.  
  273.     else
  274.     { /* try to read more data */
  275.     register char *dest = yy_ch_buf;
  276.     register char *source = yy_b_buf_p - 1; /* copy prev. char, too */
  277.     register int number_to_move, i;
  278.     int ret_val;
  279.     
  280.     /* first move last chars to start of buffer */
  281.     number_to_move = yy_c_buf_p - yy_b_buf_p;
  282.  
  283.     for ( i = 0; i < number_to_move; ++i )
  284.         *(dest++) = *(source++);
  285.  
  286.     if ( yy_eof_has_been_seen )
  287.         /* don't do the read, it's not guaranteed to return an EOF,
  288.          * just force an EOF
  289.          */
  290.         yy_n_chars = 0;
  291.  
  292.     else
  293.         /* read in more data */
  294.         YY_INPUT( (&yy_ch_buf[number_to_move]), yy_n_chars,
  295.               YY_BUF_SIZE - number_to_move - 1 );
  296.  
  297.     if ( yy_n_chars == 0 )
  298.         {
  299.         if ( number_to_move == 1 )
  300.         ret_val = EOB_ACT_END_OF_FILE;
  301.         else
  302.         ret_val = EOB_ACT_LAST_MATCH;
  303.  
  304.         yy_eof_has_been_seen = 1;
  305.         }
  306.  
  307.     else
  308.         ret_val = EOB_ACT_RESTART_SCAN;
  309.  
  310.     yy_n_chars += number_to_move;
  311.     yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  312.     yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  313.  
  314.     /* yy_b_buf_p begins at the second character in
  315.      * yy_ch_buf; the first character is the one which
  316.      * preceded it before reading in the latest buffer;
  317.      * it needs to be kept around in case it's a
  318.      * newline, so yy_get_previous_state() will have
  319.      * with '^' rules active
  320.      */
  321.  
  322.     yy_b_buf_p = &yy_ch_buf[1];
  323.  
  324.     return ( ret_val );
  325.     }
  326.     }
  327.  
  328.  
  329. /* yy_get_previous_state - get the state just before the eob char was reached
  330.  *
  331.  * synopsis
  332.  *     YY_CS_TYPE yy_get_previous_state();
  333.  */
  334.  
  335. static YY_CS_TYPE yy_get_previous_state()
  336.  
  337.     {
  338.     register YY_CS_TYPE yy_cur_state;
  339.     register char *yy_temp_char_ptr;
  340.  
  341.     YY_FIND_START_STATE( yy_cur_state );
  342.  
  343.     for ( yy_temp_char_ptr = yy_b_buf_p; yy_temp_char_ptr < yy_c_buf_p; )
  344.     YY_GET_NEXT_STATE;
  345.  
  346.     return ( yy_cur_state );
  347.     }
  348.  
  349.  
  350. static unput( c )
  351. int c;
  352.  
  353.     {
  354.     YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */
  355.  
  356.     if ( yy_c_buf_p < yy_ch_buf + 2 )
  357.     { /* need to shift things up to make room */
  358.     register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
  359.     register char *dest = &yy_ch_buf[YY_BUF_SIZE + 2];
  360.     register char *source = &yy_ch_buf[number_to_move];
  361.  
  362.     while ( source > yy_ch_buf )
  363.         *--dest = *--source;
  364.  
  365.     yy_c_buf_p += dest - source;
  366.     yy_b_buf_p += dest - source;
  367.  
  368.     if ( yy_c_buf_p < yy_ch_buf + 2 )
  369.         YY_FATAL_ERROR( "flex scanner push-back overflow" );
  370.     }
  371.  
  372.     if ( yy_c_buf_p > yy_b_buf_p && yy_c_buf_p[-1] == '\n' )
  373.     yy_c_buf_p[-2] = '\n';
  374.  
  375.     *--yy_c_buf_p = c;
  376.  
  377.     YY_DO_BEFORE_ACTION; /* set up yytext again */
  378.     }
  379.  
  380.  
  381. static int input()
  382.  
  383.     {
  384.     int c;
  385.  
  386.     YY_DO_BEFORE_SCAN;
  387.  
  388.     if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  389.     { /* need more input */
  390.     yy_b_buf_p = yy_c_buf_p;
  391.     ++yy_c_buf_p;
  392.  
  393.     switch ( yy_get_next_buffer() )
  394.         {
  395.         /* this code, unfortunately, is somewhat redundant with
  396.          * that above
  397.          */
  398.         case EOB_ACT_END_OF_FILE:
  399.         {
  400.         if ( yywrap() )
  401.             {
  402.             yy_c_buf_p = yy_b_buf_p;
  403.             return ( EOF );
  404.             }
  405.  
  406.         yy_ch_buf[0] = '\n';
  407.         yy_n_chars = 1;
  408.         yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  409.         yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  410.         yy_eof_has_been_seen = 0;
  411.  
  412.         YY_FAST_INIT;
  413.  
  414.         return ( input() );
  415.         }
  416.         break;
  417.  
  418.         case EOB_ACT_RESTART_SCAN:
  419.         yy_c_buf_p = yy_b_buf_p;
  420.         break;
  421.  
  422.         case EOB_ACT_LAST_MATCH:
  423.         YY_FATAL_ERROR( "unexpected last match in input()" );
  424.         }
  425.     }
  426.  
  427.     c = *yy_c_buf_p++;
  428.  
  429.     YY_DO_BEFORE_RESTART;
  430.  
  431.     return ( c );
  432.     }
  433.